<template>
  <div class="EmergencyList">
    <div class="flex location-wrap">
      <span class="white">当前位置：</span>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/EWManagement' }">预警管理</el-breadcrumb-item>
        <el-breadcrumb-item>预警信息</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="box">
      <!-- 列表筛选 -->
      <filterTitle @query="query" @reset="reset" :form="form" labelWidth="140px" :formData="formData">
        <!-- <el-form slot="filter" class="form" ref="form" :model="form" inline size="small" label-width="140px">
          <el-form-item :label="item.label + '：'" v-for="(item, index) in formData" :key="index" :prop="item.id">
            <LsdForm :compData="item" :form="form" />
          </el-form-item>
        </el-form> -->
      </filterTitle>
      <!-- 列表表格 -->
      <LsdTable slot="gjxm" @select="handleSelectionChange" @select-all="handleSelectionChange"
        :paginationAtrrs="paginationAtrrs" @pageChange="handleSizeChange" :compRef="table.compRef" ref="gjxm"
        :columns="table.columns" :title="table.title" :actions="table.actions" :tableData="table.tableData"
        :tableAttr="table.tableAttr" :isShowPage="table.isShowPage" :isSelectFlag="table.isSelectFlag"
        :isSequenceFlag="table.isSequenceFlag" @onActionClick="onActionClick" />
    </div>
    <!-- 弹窗信息 -->
    <LsdDialog :dialogConfig="dialogConfig" @handleBtn="handleBtn" @close="close">
      <LsdDialogTitle slot="dialog" :titleConfig="titleConfig" :activeNames="activeNames">
        <DialogForm ref="formComponent" slot="slot1" :formConfig="formConfig" />
        <DialogForm ref="formComponent1" @pickerChange="pickerChange" slot="slot2" @removeTag="removeTag"
          @handleNodeClick="handleNodeClick" @handlePreview="handlePreview" @handleRemove="handleRemove"
          @handleBeforeUpload="handleBeforeUpload" :formConfig="formConfig1" @handleChange="handleChange" />
        <DialogForm ref="formComponent2" slot="slot3" :formConfig="formConfig2" />
      </LsdDialogTitle>
    </LsdDialog>
  </div>
</template>

<script>
import {
  // listPage,
  deleteByIds,
  updById,
  saveAdd,
  getById,
  warningInfoSubmit,
  getIssueNoticeList, getCityTree, listPagey
} from "@/api/EarlyWarningManagement/yjxxsj";

import { getDictByGroup, UploadFile, loadFile } from "@/api/common.js";
import { showTime } from "@/lib";
export default {
  name: "InformationList",
  components: {},
  data() {
    return {
      type: 0, // 区分编辑和新增
      multipleSelection: [], // 单选全选
      // 筛选信息
      formData: [
        {
          elType: "input",
          id: "warningInfo",
          label: "预警信息",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            "collapse-tags": true
          }
        },
        {
          elType: "select",
          id: "dangerCode",
          label: "险情类别",
          dic: "dic_xqlb",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            filterable: true,
            "collapse-tags": true
          },
          options: []
        },
        {
          elType: "select",
          id: "warningLvCode",
          label: "预警级别",
          dic: "dic_yjjb",
          attrs: {
            value: "",
            clearable: true,
            size: "small",
            filterable: true,
            "collapse-tags": true
          },
          options: []
        },
        {
          elType: "input",
          id: "effectRange",
          label: "影响范围",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            filterable: true,
            "collapse-tags": true
          }
        },
        {
          elType: "dateTimePicker",
          id: "effectStartTime",
          label: "影响时间",
          attrs: {
            value: "",
            size: "small",
            type: "datetimerange",
            clearable: true,
            "start-placeholder": "开始日期",
            "end-placeholder": "结束日期",
            "value-format": "yyyy-MM-dd HH:mm:ss"
          }
        },
        {
          elType: "select",
          id: "infoSource",
          label: "信息来源",
          dic: "dic_xxly",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            filterable: true,
            "collapse-tags": true
          },
          options: []
        },
        {
          elType: "select",
          id: "noticeId",
          label: "关联预警通知单",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            filterable: true,
            "collapse-tags": true
          },
          options: []
        },
        {
          elType: "select",
          id: "warningInfoStatus",
          label: "状态",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            filterable: true,
            "collapse-tags": true
          },
          options: [
            { label: "编辑中", value: "0" },
            { label: "未处理", value: "1" },
            { label: "已处理", value: "2" }
          ]
        }
      ],
      formData1: [
        {
          elType: "input",
          id: "warningInfo",
          label: "预警信息",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            "collapse-tags": true
          }
        },
        {
          elType: "select",
          id: "dangerCode",
          label: "险情类别",
          dic: "dic_xqlb",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            filterable: true,
            "collapse-tags": true
          },
          options: []
        },
        {
          elType: "select",
          id: "warningLvCode",
          label: "预警级别",
          dic: "dic_yjjb",
          attrs: {
            value: "",
            clearable: true,
            size: "small",
            filterable: true,
            "collapse-tags": true
          },
          options: []
        },
        {
          elType: "input",
          id: "effectRange",
          label: "影响范围",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            filterable: true,
            "collapse-tags": true
          }
        },
        {
          elType: "dateTimePicker",
          id: "effectStartTime",
          label: "影响时间",
          attrs: {
            value: "",
            size: "small",
            type: "datetimerange",
            clearable: true,
            "start-placeholder": "开始日期",
            "end-placeholder": "结束日期",
            "value-format": "yyyy-MM-dd HH:mm:ss"
          }
        },
        {
          elType: "select",
          id: "infoSource",
          label: "信息来源",
          dic: "dic_xxly",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            filterable: true,
            "collapse-tags": true
          },
          options: []
        },
        {
          elType: "select",
          id: "noticeId",
          label: "关联预警通知单",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            filterable: true,
            "collapse-tags": true
          },
          options: []
        },
        {
          elType: "select",
          id: "warningInfoStatus",
          label: "状态",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            filterable: true,
            "collapse-tags": true
          },
          options: [
            { label: "编辑中", value: "0" },
            { label: "未处理", value: "1" },
            { label: "已处理", value: "2" }
          ]
        }
      ],
      formData2: [
        {
          elType: "input",
          id: "warningInfo",
          label: "预警信息",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            "collapse-tags": true
          }
        },
        {
          elType: "select",
          id: "dangerCode",
          label: "险情类别",
          dic: "dic_xqlb",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            filterable: true,
            "collapse-tags": true
          },
          options: []
        },
        {
          elType: "select",
          id: "warningLvCode",
          label: "预警级别",
          dic: "dic_yjjb",
          attrs: {
            value: "",
            clearable: true,
            size: "small",
            filterable: true,
            "collapse-tags": true
          },
          options: []
        },
        {
          elType: "input",
          id: "effectRange",
          label: "影响范围",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            filterable: true,
            "collapse-tags": true
          }
        },
        {
          elType: "dateTimePicker",
          id: "effectStartTime",
          label: "影响时间",
          attrs: {
            value: "",
            size: "small",
            type: "datetimerange",
            clearable: true,
            "start-placeholder": "开始日期",
            "end-placeholder": "结束日期",
            "value-format": "yyyy-MM-dd HH:mm:ss"
          }
        },
        {
          elType: "select",
          id: "infoSource",
          label: "信息来源",
          dic: "dic_xxly",
          attrs: {
            value: "",
            size: "small",
            clearable: true,
            filterable: true,
            "collapse-tags": true
          },
          options: []
        }
        // {
        //   elType: "select",
        //   id: "noticeId",
        //   label: "关联预警通知单",
        //   attrs: {
        //     value: "",
        //     size: "small",
        //     clearable: true,
        //     filterable: true,
        //     "collapse-tags": true
        //   },
        //   options: []
        // }
      ],
      // 表格信息
      table: {
        isSelectFlag: true, // 是否展示选择器
        compRef: "gjxm",
        isSequenceFlag: true, // 是否展示序号
        isShowPage: true, // 是否展示分页
        resetFlag: true,
        loading: false,
        title: "预警信息列表",
        actions: [
          // {
          //   id: "dialogVisible",
          //   text: "新增",
          //   type: "primary",
          //   btnAttr: { size: "small" }
          // },
          // {
          //   id: "ListAddyp",
          //   text: "研判",
          //   type: "",
          //   btnAttr: { size: "small" }
          // }
        ],
        tableData: [],
        columns: [
          {
            prop: "warningInfo",
            label: "预警信息",
            align: "left",
            "min-width": "190px",
            render: (h, { row }) => {
              return (
                <div>
                  {
                    <span
                      style='width: 100%;' class='commonTableStyle'
                      {...{
                        on: {
                          click: () => {
                            this.detailList(row);
                          }
                        }
                      }}
                    >
                      {row.warningInfo}
                    </span>
                  }
                </div>
              );
            }
          },
          {
            prop: "dangerName",
            label: "险情类别",
            align: "center",
            "min-width": "60px"
          },
          {
            prop: "warningLvName",
            label: "预警级别",
            align: "center",
            "min-width": "60px"
          },
          {
            prop: "effectRange",
            label: "影响范围",
            align: "left",
            "min-width": "120px"
          },
          {
            prop: "effectEndTime",
            label: "影响时间",
            align: "left",
            "min-width": "120px",
            render: (h, { row }) => {
              return (
                <div>
                  {
                    <span>
                      {row.effectStartTime}至{row.effectEndTime}
                    </span>
                  }
                </div>
              );
            }
          },
          {
            prop: "infoSourceName",
            label: "信息来源",
            align: "center"
          },
          {
            prop: "warningNoticeName",
            label: "关联预警通知单",
            align: "left",
            "min-width": "250px",
            render: (h, { row }) => {
              return (
                <div>
                  {
                    <span
                      style='width: 100%;' class='commonTableStyle'
                      {...{
                        on: {
                          click: () => {
                            console.log(row);
                            this.$router.push({
                              name: "NoticeDetail",
                              query: { id: row.noticeId }
                            });
                          }
                        }
                      }}
                    >
                      {row.warningNoticeName}
                    </span>
                  }
                </div>
              );
            }
          },
          {
            prop: "warningInfoStatus",
            label: "状态",
            align: "center",
            "min-width": "100px",
            formatter: (row, column, cellValue, index) => {
              if (cellValue === "0") {
                return "编辑中";
              } else if (cellValue === "1") {
                return "未处理";
              } else if (cellValue === "2") {
                return "已处理";
              }
            }
          },
          {
            prop: "cz",
            label: "操作",
            align: "center",
            fixed: "right",
            "min-width": "100px",
            render: (h, { row }) => {
              const tbPower = this.common.isHasPower("tbr");
              return (
                <div>
                  {
                    <span
                      style='color:#3561fd;cursor:pointer;margin:0 10px'
                      {...{
                        on: {
                          click: () => {
                            this.HanEdit(row);
                          }
                        }
                      }}
                    >
                      {row.warningInfoStatus === "0" && tbPower ? "编辑" : ""}
                    </span>
                  }
                  {
                    <span
                      style='color:#3561fd;cursor:pointer;'
                      {...{
                        on: {
                          click: () => {
                            this.detailForm(row);
                          }
                        }
                      }}
                    >
                      {row.warningInfoStatus === "0" && tbPower ? "删除" : ""}
                    </span>
                  }
                </div>
              );
            }
          }
        ],
        // 表格样式
        tableAttr: {
          // "max-height": "430px",
          // height: "430px",
          border: true,
          fit: true,
          stripe: true,
          "show-header": true,
          "highlight-current-row": true,
          "cell-style": {
            "font-size": "16px"
          },
          "header-cell-style": {
            "text-align": "center",
            "background-color": "#B1C8F9",
            border: "1px solid #ccc",
            "font-size": "16px"
          }
        }
      },
      // 分页信息
      paginationAtrrs: {
        total: 0,
        "background": true,
        layout: "prev, pager, next",
        "current-page": 1,
        "page-size": 10
      },
      activeNames: ["1", "2", "3"], // 折叠面板默认展开列
      form: {}, // 筛选from
      pageNum: 1,
      pageSize: 10,
      // 弹窗信息
      dialogConfig: {
        title: "预警信息录入",
        isShow: false, // 弹窗显示隐藏
        btnList: [
          {
            name: "报送",
            id: "BSubmit", // 事件名
            type: "primary",
            size: "small"
          },
          {
            name: "保存",
            id: "submitForm",
            size: "small"
          },
          {
            name: "取消",
            id: "Qxiao",
            size: "small"
          }
        ]
      },
      // 折叠面板信息
      titleConfig: [
        {
          title: "信息来源",
          name: "1",
          slot: "slot1"
        },
        {
          title: "基本信息",
          name: "2",
          slot: "slot2"
        },
        {
          title: "填报信息",
          name: "3",
          slot: "slot3"
        }
      ],
      // 弹窗表单信息
      formConfig: {
        formData: [
          {
            type: "select",
            label: "信息来源",
            prop: "infoSource",
            name: "infoSourceName",
            dic: "dic_xxly",
            class: "half",
            lableWidth: "130px",
            option: []
          }
        ],
        rules: {
          infoSource: [
            { required: true, message: "请选择信息来源", trigger: "change" }
          ]
        }
      },
      // 弹窗表单信息
      formConfig1: {
        formData: [
          {
            type: "input",
            label: "预警信息",
            prop: "warningInfo",
            class: "sjgy",
            lableWidth: "130px"
          },
          {
            type: "select",
            label: "险情类别",
            prop: "dangerCode",
            dic: "dic_xqlb",
            name: "dangerName",
            class: "half",
            lableWidth: "130px",
            option: []
          },
          {
            type: "select",
            label: "预警级别",
            prop: "warningLvCode",
            name: "warningLvName",
            dic: "dic_yjjb",
            class: "half",
            lableWidth: "130px",
            option: []
          },
          // {
          //   type: "input",
          //   label: "影响范围",
          //   prop: "effectRange",
          //   class: "half",
          //   lableWidth: "130px"
          // },
          {
            type: "selectTree",
            label: "影响范围",
            prop: "effectRange",
            name: "geo",
            title: "影响范围选择",
            choose: false,
            keyWord: "keyWord",
            treeRef: "treeRef",
            commonClick: false,
            ref: "tree_select1",
            class: "half",
            multiple: true,
            lableWidth: "130px",
            option: [],
            treeData: {
              data: [],
              checked: [],
              props: {
                children: "children",
                label: "extName",
                value: "geo"
              }
            }
          },
          {
            type: "dataPicker",
            label: "影响时间",
            prop: "effectStartTime",
            start: "effectStartTime",
            end: "effectEndTime",
            class: "half",
            dateType: "datetimerange",
            lableWidth: "130px"
          },
          {
            type: "textarea",
            label: "事件概要",
            prop: "incidentOutline",
            class: "sjgy",
            lableWidth: "130px"
          },
          {
            type: "upload",
            label: "附件",
            prop: "ztqks",
            action: "#",
            autoUpload: true,
            lableWidth: "130px",
            tip: "支持jpg/png/pdf/doc等文件，且不超过20mb"
          }
        ],
        rules: {
          warningInfo: [
            {
              required: true,
              message: "请输入预警信息名称",
              trigger: "change"
            }
          ],
          warningLvCode: [
            { required: true, message: "请选择预警级别", trigger: "change" }
          ],
          effectRange: [
            { required: true, message: "请选择影响范围", trigger: "blur" }
          ],
          incidentOutline: [
            { required: true, message: "请输入事件概要", trigger: "change" }
          ],
          effectStartTime: [
            { required: true, message: "请选择影响时间", trigger: "change" }
          ],
          dangerCode: [
            { required: true, message: "请选择险情类别", trigger: "change" }
          ]
        }
      },
      // 弹窗表单信息
      formConfig2: {
        formData: [
          {
            type: "input",
            label: "填报人",
            prop: "creator",
            isDisabled: true,
            class: "third",
            lableWidth: "130px"
          },
          {
            type: "input",
            label: "单位及部门",
            class: "third",
            isDisabled: true,
            prop: "unitDeptName",
            lableWidth: "130px"
          },
          {
            type: "input",
            label: "填报时间",
            class: "third",
            isDisabled: true,
            prop: "createTime",
            lableWidth: "130px"
          }
        ]
      },
      fid: "",
      FilledBy: {},
      effectRangeId: "",
      rangeInfo: [],
      fileSize: ""
    };
  },
  watch: {
    "$route.query.warningInfoStatus": {
      handler() {
        if (this.$route.query.warningInfoStatus == 1) {
          this.$set(this.table, "actions", [
            {
              id: "ListAddyp",
              text: "研判",
              type: "primary",
              btnAttr: { size: "small" }
            }
          ]);
        } else {
          this.$set(this.table, "actions", [
            {
              id: "dialogVisible",
              text: "新增",
              type: "primary",
              btnAttr: { size: "small" }
            }
          ]);

        }
        if (this.$route.query.warningInfoStatus) {
          this.formData = this.formData2;
        } else {

          this.formData = this.formData1;
        }
        this.getInputVal();
        this.getIssueNoticeList();
        this.list();
      },
      deep: true
    }
  },
  mounted() {
    this.list();
    this.getInputVal();
    this.getUnitTree();
    this.getIssueNoticeList();
    if (JSON.parse(sessionStorage.getItem("role")).roleCode === "province_company_leadership") {
      this.table.actions = [];
    }
    const FilledBy = {
      creator: JSON.parse(sessionStorage.getItem("account")).realName,
      creatorId: JSON.parse(sessionStorage.getItem("account")).id,
      deptId: JSON.parse(sessionStorage.getItem("org")).orgCode,
      // unitDeptName: JSON.parse(sessionStorage.getItem("org")).orgName,
      unitDeptName: sessionStorage.getItem("dwbmName"),
      createTime: showTime(new Date())
    };
    this.FilledBy = FilledBy;
  },
  created() {
    if (this.$route.query.warningInfoStatus == 1) {
      this.$set(this.table, "actions", [
        {
          id: "ListAddyp",
          text: "研判",
          type: "primary",
          btnAttr: { size: "small" }
        }
      ]);
    } else {
      this.$set(this.table, "actions", [
        {
          id: "dialogVisible",
          text: "新增",
          type: "primary",
          btnAttr: { size: "small" }
        }
      ]);

    }
    if (this.$route.query.warningInfoStatus) {
      this.formData = this.formData2;
    } else {

      this.formData = this.formData1;
    }
    this.getInputVal();
    this.getIssueNoticeList();
  },
  methods: {
    // 树状接口
    getUnitTree() {
      getCityTree().then(res => {
        this.formConfig1.formData[3].treeData.data = res;
      });
    },
    // 影响范围
    handleNodeClick(data, node, item) {
      if (item.label === "影响范围") {
        const result = this.$refs.formComponent1.form.effectRange;
        const datas = data.children || [];
        if (datas.length > 0) {
          if (result.includes(data.extName)) return;
          else {
            this.$refs.formComponent1.form.effectRange.push(data.extName);
            this.$refs.formComponent1.form.geo.push(data.geo);
            const obj = { effectRange: data.extName, locationId: data.id, geo: data.geo, locationDeep: Number(data.deep) };
            this.rangeInfo.push(obj);
            console.log(this.rangeInfo, "this.rangeInfo1111111");
            console.log(this.$refs.formComponent1.form.effectRange, "this.$refs.formComponent1.form.effectRange");
          }
        } else {
          if (result.includes(`${node.parent.data.extName}${data.extName}`) || result.includes(`${data.extName}`)) return;
          else {
            if (node.parent.data.extName) {
              this.$refs.formComponent1.form.effectRange.push(`${node.parent.data.extName}${data.extName}`);
              const obj = { effectRange: `${node.parent.data.extName}${data.extName}`, locationId: data.id, geo: data.geo, locationDeep: Number(data.deep) };
              this.rangeInfo.push(obj);
            } else {
              const obj = { effectRange: `${data.extName}`, locationId: data.id, geo: data.geo, locationDeep: Number(data.deep) };
              this.$refs.formComponent1.form.effectRange.push(`${data.extName}`);
              this.rangeInfo.push(obj);
            }
            this.$refs.formComponent1.form.geo.push(data.geo);
          }
        }
      }
    },
    // 多选删除
    removeTag(val) {
      this.rangeInfo.splice(this.rangeInfo.findIndex(item => item.effectRange === val), 1);
    },
    getIssueNoticeList() {
      this.formData.forEach((item) => {
        if (item.label === "关联预警通知单") {
          getIssueNoticeList({ pageNum: 1, pageSize: 10 }).then(res => {
            const option = res.data.map((item) => {
              return {
                label: item.warningNoticeName,
                value: item.id
              };
            });
            item.options = option;
          });
        }
      });
    },
    handleBeforeUpload(file) {
      const maxFileSize = 20 * 1024 * 1024;
      let flag = true;
      if (this.fileSize > maxFileSize) {
        this.$message({
          message: "上传文件大小不得大于20MB!",
          type: "error"
        });
        this.$refs.formComponent1.fileList = [];
        flag = false;
      }
      if (flag) {
        const parmas = {
          file: file,
          directoryId: 0,
          isNew: false,
          moduleName: "EmergencyEvent"
        };
        UploadFile(this.common.convertFormData(parmas)).then(data => {
          this.$nextTick(() => {
            this.$refs.formComponent1.fileList.push({ name: data.fileName, attachId: data.id });
          });
        });
      }

    },
    handleChange(event) {
      this.fileSize = event.size; // 获取文件大小
      // const fileName = file.name;
      // const uid = file.uid;
      // const pos = fileName.lastIndexOf(".");
      // const lastName = fileName.substring(pos, fileName.length);
      // if (
      //   lastName.toLowerCase() !== ".jpg" &&
      //   lastName.toLowerCase() !== ".png" &&
      //   lastName.toLowerCase() !== ".doc" &&
      //   lastName.toLowerCase() !== ".pdf"
      // ) {
      //   this.$message({
      //     message: "文件必须为.jpg .png .doc .pdf 类型",
      //     type: "error"
      //   });
      //   for (var i = 0; i < fileList.length; i++) {
      //     if (fileList[i].uid == uid) {
      //       fileList.splice(i, 1);
      //     }
      //   }
      //   this.formConfig1.formData[6].autoUpload = false;
      //   return;
      // } else {
      //   this.formConfig1.formData[6].autoUpload = true;
      // }
      // // 限制上传文件的大小
      // const isLt = file.size / 1024 / 1024 / 50 <= 1;
      // if (!isLt) {
      //   this.$message({
      //     message: "上传文件大小不得大于50MB!",
      //     type: "error"
      //   });
      //   for (var i = 0; i < fileList.length; i++) {
      //     if (fileList[i].uid == uid) {
      //       fileList.splice(i, 1);
      //     }
      //   }
      // }
      // return isLt;
    },
    // 下载
    handlePreview(item) {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.6)"
      });
      loadFile({ id: item.attachId }).then(res => {
        const a = document.createElement("a");
        const objectUrl = URL.createObjectURL(res);
        a.setAttribute("href", objectUrl);
        a.setAttribute("download", item.name);
        a.click();
        loading.close();
      }).catch(() => {
        loading.close();
      });
    },
    // 删除
    handleRemove(file, fileList) {
      this.$set(this.$refs.formComponent1, "fileList", fileList);
    },
    // 弹窗按钮点击事件 对应id绑定事件
    handleBtn(item) {
      this[item.id]();
    },
    // 重置
    reset() {
      this.form = this.$options.data().form;
      this.$refs.gjxm.paginationAtrrsInner["current-page"] = 1;
      this.list();
    },
    // 检索
    async query() {
      let sta = "";
      if (this.$route.query.warningInfoStatus) {
        sta = this.$route.query.warningInfoStatus;
      } else {
        sta = this.form.warningInfoStatus;
      }
      const parmas = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        warningInfo: this.form.warningInfo,
        dangerCode: this.form.dangerCode,
        warningLvCode: this.form.warningLvCode,
        effectRange: this.form.effectRange,
        effectStartTime: this.form.effectStartTime ? this.form.effectStartTime[0] : "", // 开始时间
        effectEndTime: this.form.effectStartTime ? this.form.effectStartTime[1] : "", // 结束时间
        infoSource: this.form.infoSource,
        warningInfoStatus: sta,
        noticeId: this.form.noticeId,
        receiveTimes: this.form.receiveTimes
        // warningInfoStatus: this.$route.query.warningInfoStatus
      };
      const res = await listPagey(parmas);
      // const data = await listPagey({
      //   effectRange: this.form.effectRange, pageNum: this.pageNum,
      //   pageSize: this.pageSize
      // });
      // this.table.tableData = data.data;
      // this.paginationAtrrs.total = data.total;
      this.table.tableData = res.data;
      this.paginationAtrrs.total = res.total;
    },
    // 保存
    async submitForm() {
      this.$refs.formComponent.isValidate();
      this.$refs.formComponent1.isValidate();
      const flag = this.$refs.formComponent.flag;
      const flag1 = this.$refs.formComponent1.flag;
      if (flag && flag1) {
        console.log(this.$refs.formComponent1.fileList);
        const list = this.$refs.formComponent1.fileList;
        const newList = [];
        list.forEach(item => {
          newList.push(
            {
              attachName: item.name,
              attachId: item.attachId
            }
          );
        });
        const parmas = {
          dangerCode: this.$refs.formComponent1.form.dangerCode,
          dangerName: this.$refs.formComponent1.form.dangerName,
          warningLvName: this.$refs.formComponent1.form.warningLvName,
          infoSourceName: this.$refs.formComponent.form.infoSourceName,
          creator: JSON.parse(sessionStorage.getItem("account")).realName,
          creatorId: JSON.parse(sessionStorage.getItem("account")).id,
          deptId: JSON.parse(sessionStorage.getItem("org")).id,
          unitDeptName: sessionStorage.getItem("dwbmName"),
          effectEndTime: this.$refs.formComponent1.form.effectEndTime,
          // effectRange: this.$refs.formComponent1.form.effectRange,
          // geo: this.$refs.formComponent1.form.geo,
          rangeInfo: this.rangeInfo,
          effectStartTime: this.$refs.formComponent1.form.effectStartTime,
          incidentOutline: this.$refs.formComponent1.form.incidentOutline,
          infoSource: this.$refs.formComponent.form.infoSource,
          warningInfo: this.$refs.formComponent1.form.warningInfo,
          warningLvCode: this.$refs.formComponent1.form.warningLvCode,
          attachInfo: newList || []
          // locationId: this.effectRangeId
        };
        if (this.type === 1) {
          const res = await saveAdd(parmas);
          if (res) {
            this.$message({
              message: "保存成功",
              type: "success"
            });
            this.list();
            this.dialogConfig.isShow = false;
          }
        } else if (this.type === 2) {
          parmas.id = this.fid;
          const res = await warningInfoSubmit(parmas);
          if (res) {
            this.$message({
              message: "报送成功",
              type: "success"
            });
            this.list();
            this.dialogConfig.isShow = false;
          }
        } else {
          parmas.id = this.fid;
          const res = await updById(parmas);
          if (res) {
            this.$message({
              message: "修改成功",
              type: "success"
            });
            this.list();
            this.dialogConfig.isShow = false;
          }
        }
      }

    },
    // 报送
    async BSubmit() {
      this.type = 2;
      this.submitForm();
    },
    // 取消
    Qxiao() {
      this.$refs.formComponent1.fileList = [];
      this.rangeInfo = [];
      this.$refs.formComponent.form = this.$refs.formComponent.$options.data().form;
      this.$refs.formComponent1.form = this.$refs.formComponent1.$options.data().form;
      this.$refs.formComponent2.form = this.$refs.formComponent2.$options.data().form;
      this.$nextTick(() => {
        this.$refs.formComponent.$refs.formInlines.clearValidate();
        this.$refs.formComponent1.$refs.formInlines.clearValidate();
        this.$refs.formComponent2.$refs.formInlines.clearValidate();

      });
    },
    // 弹窗关闭图标
    close() {
      this.$refs.formComponent1.fileList = [];
      this.rangeInfo = [];
      this.$refs.formComponent.form = this.$refs.formComponent.$options.data().form;
      this.$refs.formComponent1.form = this.$refs.formComponent1.$options.data().form;
      this.$refs.formComponent2.form = this.$refs.formComponent2.$options.data().form;
      this.$nextTick(() => {
        this.$refs.formComponent.$refs.formInlines.clearValidate();
        this.$refs.formComponent1.$refs.formInlines.clearValidate();
        this.$refs.formComponent2.$refs.formInlines.clearValidate();

      });
      this.dialogConfig.isShow = false;
    },
    // 获取下拉框数据
    getInputVal() {
      this.formData.forEach((item) => {
        if (item.dic) {
          getDictByGroup({ groupCode: item.dic }).then(res => {
            const option = res.map((item) => {
              return {
                label: item.dicName,
                value: Number(item.dicCode)
              };
            });
            item.options = option;
          });
        }
      });
      this.formConfig.formData.forEach((item) => {
        if (item.dic) {
          getDictByGroup({ groupCode: item.dic }).then(res => {
            const option = res.map((item) => {
              return {
                label: item.dicName,
                value: Number(item.dicCode)
              };
            });
            item.option = option;
          });
        }
      });
      this.formConfig1.formData.forEach((item) => {
        if (item.dic) {
          getDictByGroup({ groupCode: item.dic }).then(res => {
            const option = res.map((item) => {
              return {
                label: item.dicName,
                value: Number(item.dicCode)
              };
            });
            item.option = option;
          });
        }
      });
    },
    // 列表
    async list() {
      let sta = "";
      if (this.$route.query.warningInfoStatus) {
        sta = this.$route.query.warningInfoStatus;
      } else {
        sta = this.form.warningInfoStatus;
      }
      const parmas = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        warningInfoStatus: sta
      };
      const res = await listPagey(parmas);
      this.table.tableData = res.data;
      this.paginationAtrrs.total = res.total;
    },
    // 抛出列表按钮
    onActionClick(item, index) {
      this[item.id](); // 调用按钮对应方法
    },
    // 新增
    dialogVisible() {
      this.dialogConfig.isShow = true;
      this.type = 1;
      this.$nextTick(() => {
        this.$refs.formComponent2.form = this.FilledBy;
        this.$set(this.$refs.formComponent1.form, "effectRange", []);
        this.$set(this.$refs.formComponent1.form, "geo", []);
        // this.$refs.formComponent1.form.effectRange = [];
        // this.$refs.formComponent1.form.geo = [];
      });
    },
    // 详情
    detailList(id) {
      this.$router.push({
        name: "InformationDetail",
        query: { id: id.id }
      });
    },
    // 研判
    ListAddyp() {
      if (this.multipleSelection.length <= 0) {
        this.$message({
          message: "请至少选择一条数据",
          type: "warning"
        });
      } else if (this.multipleSelection.length >= 1) {
        this.isSame = true;
        const firstQdr = this.multipleSelection[0].dangerName;
        const operate = this.multipleSelection[0].operate;
        try {
          this.multipleSelection.forEach((item, index) => {
            if (item.dangerName != firstQdr || item.warningInfoStatus !== "1" || item.isJudge !== "0") {
              this.$message({
                message: "请选择险情类别相同(且为状态为已报送,未进行预警研判)的进行研判！",
                type: "warning"
              });
              this.isSame = false;
              throw new Error("error");
            } else if (item.operate === false) {
              this.$message({
                message: "禁止操作其他单位的单据！",
                type: "warning"
              });
              this.isSame = false;
              throw new Error("error");
            } else if (item.operate != operate) {
              this.$message({
                message: "选择的单据包含其他单位的单据，请检查！",
                type: "warning"
              });
              this.isSame = false;
              throw new Error("error");
            }
          });
        } catch (error) {
          console.log(error);
        }
        var str = "";
        for (var i = 0; i < this.multipleSelection.length; i++) {
          str += this.multipleSelection[i].id + ",";
        }

        // 去掉最后一个逗号(如果不需要去掉，就不用写)
        if (str.length > 0) {
          str = str.substr(0, str.length - 1);
        }
        if (this.isSame) {
          this.$router.push({
            name: "EarlyJudgmentList",
            query: {
              id: str,
              type: 1,
              types: 2
            }
          });
        }
      }
    },
    // 选择器
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 编辑
    HanEdit(id) {
      this.dialogConfig.isShow = true;
      getById({ id: id.id }).then(res => {
        this.type = 0;
        this.fid = res.id;
        this.rangeInfo = res.rangeDetailVos;
        this.$nextTick(() => {
          const effectRange = [];
          const geo = [];
          res.rangeDetailVos.map(item => {
            effectRange.push(item.effectRange);
            geo.push(item.geo);
          });
          this.$set(this.$refs.formComponent1.form, "effectRange", effectRange);
          this.$set(this.$refs.formComponent1.form, "geo", geo);
        });
        this.$set(this.$refs.formComponent1.form, "dangerName", res.dangerName);
        this.$set(this.$refs.formComponent1.form, "dangerCode", Number(res.dangerCode));
        this.$set(this.$refs.formComponent1.form, "warningLvName", res.warningLvName);
        this.$set(this.$refs.formComponent1.form, "warningLvCode", Number(res.warningLvCode));
        this.$set(this.$refs.formComponent1.form, "incidentOutline", res.incidentOutline);

        this.$set(this.$refs.formComponent1.form, "warningInfo", res.warningInfo);
        this.$set(this.$refs.formComponent.form, "infoSource", Number(res.infoSource));
        this.$set(this.$refs.formComponent.form, "infoSourceName", res.infoSourceName);
        this.$refs.formComponent2.form = res;
        this.$set(this.$refs.formComponent1.form, "effectStartTime", res.effectStartTime);
        this.$set(this.$refs.formComponent1.form, "effectEndTime", res.effectEndTime);
        const list = res.attachInfo;
        const newList = [];
        list.forEach(item => {
          newList.push({
            name: item.attachName,
            attachId: item.attachId
          });
        });
        this.$set(this.$refs.formComponent1, "fileList", newList);


      });
    },

    // 列表删除
    detailForm(id) {
      this.$confirm("此操作将永久删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        deleteByIds([id.id]).then(data => {
          if (data) {
            this.$message({
              message: "删除成功",
              type: "success"
            });
            this.list();
          }
        });
      }).catch(() => {
        this.$message({
          type: "info",
          message: "已取消删除"
        });
      });
    },
    // 分页
    handleSizeChange(val) {
      this.pageNum = val["current-page"];
      this.pageSize = val["page-size"];
      // this.list();
      this.query();
    },
    // 时间提示
    pickerChange(val, item, num) {
      this.$nextTick(() => {
        if (
          this.$refs.formComponent1.form.effectStartTime &&
          this.$refs.formComponent1.form.effectEndTime
        ) {
          const start = +new Date(
            this.$refs.formComponent1.form.effectStartTime
          );
          const end = +new Date(this.$refs.formComponent1.form.effectEndTime);
          if (num === 1) {
            if (start > end) {
              this.$message({
                message: "开始时间不能大于结束时间",
                type: "error"
              });
              this.$set(this.$refs.formComponent1.form, "effectStartTime", "");
            }
          } else {
            if (end < start) {
              this.$message({
                message: "结束时间不能小于开始时间",
                type: "error"
              });
              this.$set(this.$refs.formComponent1.form, "effectEndTime", "");
            }
          }
        }
      });
    }
  }
};
</script>

<style scoped lang="less">
@import "../../../assets/style/common.less";
@import "../../../assets/style/ComponentStyle.less";
@import "../../../assets/style/pop-upNotification.less";

:deep(.el-breadcrumb__inner.is-link) {
  font-weight: 100;
  color: #fff;
}

:deep(.el-dialog) {
  height: 70% !important;
  margin-top: 22vh !important;

  .dialog-footer {
    position: absolute;
    width: 20%;
    bottom: 10px;
    left: 40%;
    display: flex;
    justify-content: space-around;
  }
}

:deep(.el-table--striped .el-table__body tr.el-table__row--striped.el-table__row--striped.el-table__row--striped td) {
  background-color: #f8f9f8;
  /*隔行变色*/
}

//鼠标悬浮样式
:deep(tr.hover-row) {

  &,
  &.el-table__row--striped {

    &,
    &.current-row {
      >td.el-table__cell {
        background: none;
      }
    }
  }
}

.EmergencyList {
  height: 97% !important;
}

.EmergencyList :deep(.el-breadcrumb__item:last-child .el-breadcrumb__inner) {
  color: #3270ff;
}

.box {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-top: 15px;
  background-color: #fff;
  border-radius: 4px;
  padding: 10px;
  box-sizing: border-box;
}

:deep(.el-breadcrumb) {
  font-size: 16px;
  line-height: initial;
}

:deep(.el-tag__close) {
  background-color: rgba(185, 206, 250) !important;
  color: #333333 !important;
  border-radius: 0px !important;
  height: 25px;
  font-size: 15px !important;
  border: none !important;
}

:deep(.el-tag.el-tag--info) {
  background-color: rgba(185, 206, 250) !important;
  color: #333333 !important;
  border-radius: 0px !important;
  height: 25px;
  font-size: 15px !important;
  border: none !important;
}
</style>
